<template>
  <el-row :gutter="20" class="panel-group">
    <el-col v-for="item in list" :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper">
          <img :src="item.img" alt="">
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            {{ item.name }}
          </div>
          <count-to :start-val="0" :end-val="Number(listInfo[item.key])" :duration="2000" class="card-panel-num" />
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'
import { getIndexInfo } from '@/api/business/index'
export default {
  components: {
    CountTo
  },
  data() {
    return {
      listInfo: {
        assetNum: 0,
        propertyNum: 0,
        totalRent: 0,
        assetUtilization: 0
      },
      list: [
        {
          name: '房产总数量（个）',
          count: 0,
          img: require('@/assets/images/index/block1.png'),
          key: 'assetNum'
        },
        {
          name: '产权单位数量（个）',
          count: 0,
          img: require('@/assets/images/index/block2.png'),
          key: 'propertyNum'
        },
        {
          name: '租金总额（亿元）',
          count: 0,
          img: require('@/assets/images/index/block3.png'),
          key: 'totalRent'
        },
        {
          name: '房产利用率（%）',
          count: 0,
          img: require('@/assets/images/index/block4.png'),
          key: 'assetUtilization'
        }
      ]
    }
  },
  created() {
    this.getIndexInfo()
  },
  methods: {
    getIndexInfo() {
      getIndexInfo().then(res => {
        this.listInfo = res.data
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.panel-group {
  .card-panel-col {
    margin-bottom: 32px;
  }
  .card-panel {
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    background: #d7effd;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    border-radius: 20px;
    padding: 10px;
    display: flex;
    align-items: center;
    .card-panel-icon-wrapper {
      width: 30%;
      margin-right: 20px;
      transition: all 0.38s ease-out;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .card-panel-description {
      flex: 1;
      font-weight: bold;
      .card-panel-text {
        font-size: 18px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 24px;
        color: rgb(24, 143, 253);
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
